//
//  TheOne_TextFieldView.m
//  lTTheOne
//
//  Created by AA on 2024/2/20.
//

#import "TheOne_TextFieldView.h"
#import "HeaderConfig.h"
#import "objc/runtime.h"
#import "Masonry.h"
#import "UIColor+hexString.h"

@interface TheOne_TextFieldView ()



@end

@implementation TheOne_TextFieldView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.MYtextfield];
    }
    return self;
}


-(UITextField *)MYtextfield{
    
    if (!_MYtextfield) {
        
        _MYtextfield = [[UITextField alloc] initWithFrame:CGRectZero];
        _MYtextfield.returnKeyType = UIReturnKeyDone;
        //显示关闭按钮
        _MYtextfield.clearButtonMode = UITextFieldViewModeNever;
        _MYtextfield.font = KFont_M(tRealLength(18));
        _MYtextfield.textColor = [UIColor whiteColor];
//        _MYtextfield.delegate = self;
        _MYtextfield.tintColor = [UIColor whiteColor];
        
        _MYtextfield.textContentType = UITextContentTypeOneTimeCode;
        
        //光标的起始位置
        _MYtextfield.leftView  = [[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, 10.f, 0.f)];
        _MYtextfield.leftViewMode = UITextFieldViewModeAlways;
        _MYtextfield.placeholder = @"默认placeholder";
        _MYtextfield.autocapitalizationType = UITextAutocapitalizationTypeNone;
        //UIButton *ClearButton = [_MYtextfield valueForKey:@"_clearButton"];//key值是固定的
        //[ClearButton setImage:[UIImage imageNamed:@"清空-24"] forState:UIControlStateNormal];
        //[ClearButton setImage:[UIImage imageNamed:@"清空-24"] forState:UIControlStateHighlighted];
        //外边框
//        _MYtextfield.layer.borderColor = [UIColor blackColor].CGColor;
//        _MYtextfield.layer.cornerRadius = 55/2;
//        _MYtextfield.clipsToBounds = YES;
    
       NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:_MYtextfield.placeholder];
       [placeholder addAttribute:NSForegroundColorAttributeName value:HEXColor(@"#9C9C9C") range:NSMakeRange(0, _MYtextfield.placeholder.length)];
       [placeholder addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:tRealLength(18)] range:NSMakeRange(0, _MYtextfield.placeholder.length)];
        _MYtextfield.attributedPlaceholder = placeholder;
        
        __weak typeof (self) weaktypeof = self;
        
//        _MYtextfield.backgroundColor = cust_Color(245, 245, 245, 1);//默认背景颜色
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [weaktypeof.MYtextfield mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.equalTo(weaktypeof);
            }];
        });
    }
    
    return _MYtextfield;
}
//点击下一步收起键盘
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    [self.MYtextfield resignFirstResponder];
    return YES;
}

@end
